package com.wc.AlgoOJ.DS0405_光头强的计数瓶;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/2/28 20:16
 * @description
 */
public class Main1 {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    // 存储离散化，对应的值
    static int[] a = new int[N];
    // 离散化数组的长度
    static int aLen = 1;
    // 存操作
    static int[] ops = new int[N];
    // 存操作的数
    static int[] value = new int[N];
    // 存储离散对应值的数量
    static int[] nums = new int[N];
    // 存储离散化对应值的是否存在过
    static boolean[] exist = new boolean[N];
    static int n, x;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            String op = sc.next();
            if (op.equals("add")) {
                x = 1;
            } else if (op.equals("del")) {
                x = 2;
            } else {
                x = 3;
            }
            ops[i] = x;
            // 操作的数
            x = sc.nextInt();
            value[i] = x;
            a[i] = x;
        }
        // 排序
        Arrays.sort(a, 1, n + 1);
        // 去重(双指针)
        for (int i = 1; i <= n; i++) {
            if (i > 1 && a[i] != a[i - 1]) {
                a[++aLen] = a[i];
            }
        }
        // 二分查找计算
        for (int i = 1; i <= n; i++) {
            x = find(value[i]);
            if (ops[i] == 1) {
                nums[x]++;
                exist[x] = true;
                out.println(nums[x]);
            } else if (ops[i] == 2) {
                out.println(nums[x]);
                nums[x] = 0;
            } else {
                out.print(exist[x] ? 1 : 0);
                out.println(" " + nums[x]);
            }
        }
        out.flush();
    }

    static int find(int x) {
        int l = 1, r = aLen;
        while (l < r) {
            int mid = l + r >> 1;
            if (a[mid] >= x) r = mid;
            else l = mid + 1;
        }
        return r;
    }

    static class FastReader {
        StringTokenizer st;
        BufferedReader br;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        // 是否由下一个
        boolean hasNext() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = br.readLine();
                    if (line == null)
                        return false;
                    st = new StringTokenizer(line);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }
    }
}
